/*
 * Copyright (c) 2024 Huawei Technologies Co.,Ltd.
 *
 * openGauss is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *
 * http://license.coscl.org.cn/MulanPSL2
 *
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
 * -------------------------------------------------------------------------
 *
 * log_format.cpp
 * Log format constants.
 *
 * IDENTIFICATION
 * src/gausskernel/storage/mot/core/utils/log_format.cpp
 *
 * -------------------------------------------------------------------------
 */

#include "log_format.h"
#include "logger.h"
#include "mot_log.h"

#include <cstring>

static const char *LOG_FORMAT_INTERNAL_STR = "internal";
static const char *LOG_FORMAT_EXTERNAL_STR = "external";
static const char *LOG_FORMAT_INVALID_STR = "invalid";

namespace MOT {
DECLARE_LOGGER(LogFormat, Utilities)

LogFormat LogFormatFromString(const char *logFormatStr)
{
    if (strcmp(logFormatStr, LOG_FORMAT_INTERNAL_STR) == 0) {
        return LOG_FORMAT_INTERNAL;
    } else if (strcmp(logFormatStr, LOG_FORMAT_EXTERNAL_STR) == 0) {
        return LOG_FORMAT_EXTERNAL;
    } else {
        MOT_LOG_WARN("Could not parse log format: %s", logFormatStr);
        return LOG_FORMAT_INVALID;
    }
}

const char *LogFormatToString(LogFormat logFormat)
{
    switch (logFormat) {
        case LOG_FORMAT_INTERNAL:
            return LOG_FORMAT_INTERNAL_STR;
        case LOG_FORMAT_EXTERNAL:
            return LOG_FORMAT_EXTERNAL_STR;
        case LOG_FORMAT_INVALID:
        default:
            MOT_LOG_WARN("Could not convert invalid log format %d to string", (int)logFormat);
            return LOG_FORMAT_INVALID_STR;
    }
}
} // namespace MOT
